package com.bawei.common.state

import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update

/**
 * @author ZhangRuiPeng
 * @description:
 */
class RealContainer<STATE : UiState> (state : STATE) : MutableContainer<STATE>() {
    private val _requestState = MutableStateFlow(RequestState(false,false,false))
    private val _uiState = MutableStateFlow(state)
    override val requestState: StateFlow<RequestState> = _requestState
    override val uiState: StateFlow<STATE> = _uiState


    override fun updateRequestState(action: RequestState.() -> RequestState) {
        _requestState.update{action(_requestState.value)}
    }

    override fun updateUiState(action: STATE.() -> STATE) {
        _uiState.update { action(_uiState.value) }
    }




}